// $codepro.audit.disable com.instantiations.assist.eclipse.analysis.avoidPackageScopeAuditRule, declareAsInterface, numericLiterals, spellCheckComments, spellCheckIdentifiers, spellCheckStringLiterals, handleNumericParsingErrors, com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.constructorsOnlyInvokeFinalMethods, reusableImmutables, temporaryObjectCreation, com.instantiations.assist.eclipse.analysis.unusedReturnValue
/**
 * Package gui
 */
package teamrocket.gui;  // $codepro.audit.disable packagePrefixNamingConvention -->


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import teamrocket.domain.DoctorsOrders;
import teamrocket.domain.Patient;
import teamrocket.domain.PatientInvoice;
import teamrocket.domain.Prescription;
import teamrocket.domain.Procedure;
import teamrocket.domain.TreatmentRecord;
import teamrocket.domain.User;
import teamrocket.domain.VitalSigns;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import org.jdesktop.swingbinding.JComboBoxBinding;
import org.jdesktop.swingbinding.JListBinding;
import org.jdesktop.swingbinding.SwingBindings;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 * @author James Zhang, Juan Llanes, Stephen Tapper, Will Barr
 * @version 1.0
 */
public class TRFrame extends JFrame {

	/**
	 * Field contentPane.
	 */
	private JPanel contentPane;

	/**
	 * Field tbSymptoms.
	 */
	private JTextField tbSymptoms;
	
	/**
	 * Field tbDiagnosis.
	 */
	private JTextField tbDiagnosis;
	
	/**
	 * Field tbPressure.
	 */
	private JTextField tbPressure;
	
	/**
	 * Field tbPulse.
	 */
	private JTextField tbPulse;
	
	/**
	 * Field tbTemp.
	 */
	private JTextField tbTemp;
	
	/**
	 * Field tbHeight.
	 */
	private JTextField tbHeight;
	
	/**
	 * Field tbWeight.
	 */
	private JTextField tbWeight;
	
	/**
	 * Field tbDrugName.
	 */
	private JTextField tbDrugName;
	
	/**
	 * Field tbProcedure.
	 */
	private JTextField tbProcedure;
	
	/**
	 * Field lstProcedures.
	 */
	private JList lstProcedures;
	
	/**
	 * Field lstScripts.
	 */
	private JList lstScripts;
	
	/**
	 * Field mainFrame.
	 */
	MainFrame mainFrame;
	
	/**
	 * Field patient.
	 */
	Patient patient;
	
	/**
	 * Field treatmentRecord.
	 */
	TreatmentRecord treatmentRecord;
	
	/**
	 * Field orders.
	 */
	DoctorsOrders orders;
	
	/**
	 * Field procs.
	 */
	ArrayList<Procedure> procs;
	
	/**
	 * Field scripts.
	 */
	ArrayList<Prescription> scripts;
	
	/**
	 * Field doctors.
	 */
	List<User> doctors;
	
	/**
	 * Field nurses.
	 */
	List<User> nurses; 
	
	/**
	 * Field user.
	 */
	User user;
	
	/**
	 * Field binding.
	 */
	boolean binding = false;
	
	/**
	 * Field update.
	 */
	boolean update;

	/**
	 * Field cmbNurse.
	 */
	private JComboBox cmbNurse;
	
	/**
	 * Field cmbDoctor.
	 */
	private JComboBox cmbDoctor;

	/**
	 * Field pnldrOrders.
	 */
	JPanel pnldrOrders;
	
	/**
	 * Field btnSave.
	 */
	JButton btnSave;
	
	/**
	 * Field day.
	 */
	private final List<Integer> day = new ArrayList<Integer>();{
		for (int i = 1; i <= 30; i++) {
			day.add(i);
		}
	}
	
	/**
	 * Field monthsArray.
	 */
	private final String[] monthsArray = {"JANUARY", "FEBRUARY", "MARCH",
			"APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER",
			"NOVEMBER", "DECEMBER"};
	
	/**
	 * Field months.
	 */
	private final List<String> months = new ArrayList<String>();{
		for (int i = 0; i < 12; i++){
			months.add(monthsArray[i]);
		}
	}
	
	
	/**
	 * Field year.
	 */
	private final List<Integer> year = new ArrayList<Integer>();
	
	/**
	 * Field tbPreInstructions.
	 */
	private JTextField tbPreInstructions;
	
	/**
	 * Field tbCost.
	 */
	private JTextField tbCost;
	
	/**
	 * Field tbFollowUp.
	 */
	private JTextField tbFollowUp;
	
	/**
	 * Field tbInstructions.
	 */
	private JTextField tbInstructions;{
		for (int i = 2011; i <= 2015; i++){
			year.add(i);
		}
	}

	/**
	 * Create the frame.
	
	 * @param mainFrame MainFrame
	 * @param patient Patient
	 */
	public TRFrame(MainFrame mainFrame, Patient patient) {
		this(mainFrame, patient, null);
		//here I know is a create because I have a null treatment record
	}
	
	/**
	 * Constructor for TRFrame.
	 * @param mainFrame MainFrame
	 * @param patient Patient
	 * @param tr TreatmentRecord
	 */
	public TRFrame(MainFrame mainFrame, Patient patient, TreatmentRecord tr) {
		
		this.mainFrame = mainFrame;
		this.patient = patient;
		this.treatmentRecord = tr;
		this.doctors = User.lookupAllUsersOfType("d");
		this.nurses = User.lookupAllUsersOfType("n");
		this.user = mainFrame.getUser();

		setTitle("Edit Treatment Record");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 655, 537);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		final JLabel label = new JLabel("Doctor:");
		label.setBounds(10, 123, 46, 14);
		contentPane.add(label);
		
		final JLabel label_1 = new JLabel("Weight:");
		label_1.setBounds(10, 330, 85, 14);
		contentPane.add(label_1);
		
		final JLabel label_3 = new JLabel("Nurse:");
		label_3.setBounds(10, 148, 46, 14);
		contentPane.add(label_3);
		
		final JLabel label_4 = new JLabel("Symptoms:");
		label_4.setBounds(10, 173, 59, 14);
		contentPane.add(label_4);
		
		final JLabel label_5 = new JLabel("Diagnosis:");
		label_5.setBounds(10, 198, 59, 14);
		contentPane.add(label_5);
		
		final JLabel label_6 = new JLabel("Blood Pressure:");
		label_6.setBounds(10, 227, 85, 14);
		contentPane.add(label_6);
		
		final JLabel label_7 = new JLabel("Pulse:");
		label_7.setBounds(10, 252, 85, 14);
		contentPane.add(label_7);
		
		final JLabel label_8 = new JLabel("Temperature:");
		label_8.setBounds(10, 280, 85, 14);
		contentPane.add(label_8);
		
		final JLabel label_9 = new JLabel("Height:");
		label_9.setBounds(10, 305, 85, 14);
		contentPane.add(label_9);
		
		tbSymptoms = new JTextField();
		tbSymptoms.setColumns(10);
		tbSymptoms.setBounds(110, 170, 170, 20);
		contentPane.add(tbSymptoms);
		
		tbDiagnosis = new JTextField();
		tbDiagnosis.setColumns(10);
		tbDiagnosis.setBounds(110, 195, 170, 20);
		contentPane.add(tbDiagnosis);
		
		tbPressure = new JTextField();
		tbPressure.setColumns(10);
		tbPressure.setBounds(110, 224, 170, 20);
		contentPane.add(tbPressure);
		
		tbPulse = new JTextField();
		tbPulse.setColumns(10);
		tbPulse.setBounds(110, 249, 170, 20);
		contentPane.add(tbPulse);
		
		tbTemp = new JTextField();
		tbTemp.setColumns(10);
		tbTemp.setBounds(110, 277, 170, 20);
		contentPane.add(tbTemp);
		
		tbHeight = new JTextField();
		tbHeight.setColumns(10);
		tbHeight.setBounds(110, 302, 170, 20);
		contentPane.add(tbHeight);
		
		tbWeight = new JTextField();
		tbWeight.setColumns(10);
		tbWeight.setBounds(110, 327, 170, 20);
		contentPane.add(tbWeight);
		
		final JButton btnPrintInvoiceFor = new JButton("Print Invoice for Record");
		btnPrintInvoiceFor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				final PatientInvoice invoice = new PatientInvoice();
				final HashMap<String, Object> parameters = new HashMap<String, Object>();
				parameters.put("record", treatmentRecord);
				parameters.put("filepath", "invoice.pdf");
				invoice.generate(parameters);
			}
		});
		btnPrintInvoiceFor.setBounds(10, 438, 225, 23);
		contentPane.add(btnPrintInvoiceFor);
		
		final JButton btnDelete = new JButton("Delete");
		btnDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				delete();
			}
		});
		btnDelete.setBounds(6, 404, 89, 23);
		contentPane.add(btnDelete);
		
		final JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cancel();
			}
		});
		btnCancel.setBounds(105, 404, 89, 23);
		contentPane.add(btnCancel);
		
		btnSave = new JButton("Save");
		btnSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				save();
			}
		});
		btnSave.setBounds(204, 404, 89, 23);
		contentPane.add(btnSave);
		
		cmbDoctor = new JComboBox();
		cmbDoctor.setBounds(110, 120, 170, 20);
		contentPane.add(cmbDoctor);
		
		cmbNurse = new JComboBox();
		cmbNurse.setBounds(110, 145, 170, 20);
		contentPane.add(cmbNurse);
		
		pnldrOrders = new JPanel();
		pnldrOrders.setBounds(322, 27, 307, 461);
		contentPane.add(pnldrOrders);
		pnldrOrders.setLayout(null);
		
		final JLabel lblDrugName = new JLabel("Drug Name:");
		lblDrugName.setBounds(10, 166, 85, 14);
		pnldrOrders.add(lblDrugName);
		
		final JLabel lblProcedure = new JLabel("Procedure:");
		lblProcedure.setBounds(10, 405, 85, 14);
		pnldrOrders.add(lblProcedure);
		
		tbDrugName = new JTextField();
		tbDrugName.addKeyListener(new KeyAdapter() {
			@Override
			public void keyTyped(KeyEvent arg0) {
				currentScript().setDrugName(tbDrugName.getText());
				binding = true;
				bindDrLists();
				binding = false;
			}
		});
		tbDrugName.setBounds(122, 166, 175, 20);
		pnldrOrders.add(tbDrugName);
		tbDrugName.setColumns(10);
		
		tbProcedure = new JTextField();
		tbProcedure.addKeyListener(new KeyAdapter() {
			@Override
			public void keyTyped(KeyEvent arg0) {
				currentProc().setProcedureName(tbProcedure.getText());
				binding = true;
				bindDrLists();
				binding = false;
			}
		});
		tbProcedure.setBounds(122, 402, 175, 20);
		pnldrOrders.add(tbProcedure);
		tbProcedure.setColumns(10);
		
		tbPreInstructions = new JTextField();
		tbPreInstructions.addKeyListener(new KeyAdapter() {
			@Override
			public void keyTyped(KeyEvent arg0) {
				currentScript().setInstructions(tbPreInstructions.getText());
				binding = true;
				bindDrLists();
				binding = false;
			}
		});
		tbPreInstructions.setBounds(122, 191, 175, 20);
		pnldrOrders.add(tbPreInstructions);
		tbPreInstructions.setColumns(10);
		
		final JLabel lblDrugInstructions = new JLabel("Drug Instructions:");
		lblDrugInstructions.setBounds(10, 194, 114, 14);
		pnldrOrders.add(lblDrugInstructions);
		
		final JLabel lblPrescriptions = new JLabel("Procedures:");
		lblPrescriptions.setBounds(10, 284, 277, 14);
		pnldrOrders.add(lblPrescriptions);
		
		final JLabel lblCost = new JLabel("Cost:");
		lblCost.setBounds(10, 433, 85, 14);
		pnldrOrders.add(lblCost);
		
		tbCost = new JTextField();
		tbCost.addKeyListener(new KeyAdapter() {
			@Override
			public void keyTyped(KeyEvent arg0) {
				try {
					binding = true;
					currentProc().setCost(Float.parseFloat(tbCost.getText()));
					bindDrLists();
					binding = false;
				}
				catch(NumberFormatException e){ // $codepro.audit.disable emptyCatchClause
					
				}
			}
		});
		tbCost.setColumns(10);
		tbCost.setBounds(122, 430, 175, 20);
		pnldrOrders.add(tbCost);
		
		final JLabel lblProcedures = new JLabel("Prescriptions:");
		lblProcedures.setBounds(10, 74, 70, 14);
		pnldrOrders.add(lblProcedures);
		
		final JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 91, 183, 64);
		pnldrOrders.add(scrollPane);
		
		lstScripts = new JList();
		lstScripts.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent arg0) {
				bindScript(currentScript());
				
			}
		});
		scrollPane.setViewportView(lstScripts);
		
		final JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(10, 309, 183, 85);
		pnldrOrders.add(scrollPane_1);
		
		lstProcedures = new JList();
		lstProcedures.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent arg0) {
				bindProc(currentProc());
			}
		});
		scrollPane_1.setViewportView(lstProcedures);
		
		final JLabel label_2 = new JLabel("Follow up:");
		label_2.setBounds(10, 14, 85, 14);
		pnldrOrders.add(label_2);
		
		tbFollowUp = new JTextField();
		tbFollowUp.setColumns(10);
		tbFollowUp.setBounds(122, 11, 175, 20);
		pnldrOrders.add(tbFollowUp);
		
		tbInstructions = new JTextField();
		tbInstructions.setColumns(10);
		tbInstructions.setBounds(122, 41, 175, 20);
		pnldrOrders.add(tbInstructions);
		
		final JLabel label_10 = new JLabel("Instructions:");
		label_10.setBounds(10, 44, 85, 14);
		pnldrOrders.add(label_10);
		
		final JButton btnAddProc = new JButton("Add");
		btnAddProc.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				addNewProc();
				binding = true;
				bindDrLists();
				binding = false;
			}
		});
		btnAddProc.setBounds(203, 307, 89, 23);
		pnldrOrders.add(btnAddProc);
		
		final JButton btnDeleteProc = new JButton("Delete");
		btnDeleteProc.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				procs.remove(currentProc());
				binding = true;
				bindDrLists();
				binding = false;
			}
		});
		btnDeleteProc.setBounds(203, 336, 89, 23);
		pnldrOrders.add(btnDeleteProc);
		
		final JButton btnAddScript = new JButton("Add");
		btnAddScript.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				scripts.add(new Prescription("New drug", ""));
				binding = true;
				bindDrLists();
				binding = false;
			}
		});
		btnAddScript.setBounds(198, 91, 89, 23);
		pnldrOrders.add(btnAddScript);
		
		final JButton btnDeleteScript = new JButton("Delete");
		btnDeleteScript.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				scripts.remove(currentScript());
				binding = true;
				bindDrLists();
				binding = false;
			}
		});
		btnDeleteScript.setBounds(198, 120, 89, 23);
		pnldrOrders.add(btnDeleteScript);
		
		initDataBindings(); //do it before initFileds so the combo box are selcted correctly (STILL NOT DOING IT) FIX!!!

		if(tr != null) {
			initFields(tr);
			update = true;
		}
		else {
			this.scripts = new ArrayList<Prescription>();
			this.procs = new ArrayList<Procedure>();
			btnDelete.setVisible(false);
		}
		
		if (user.getUsertype().equals("d")){
			pnldrOrders.setVisible(true);
		}
		else{
			pnldrOrders.setVisible(false);
		}
		
		
		
	}
	
	/**
	 * Method initFields.
	 * @param tr TreatmentRecord
	 */
	private void initFields(TreatmentRecord tr) {
		tbSymptoms.setText(tr.getSymptoms());
		tbDiagnosis.setText(tr.getDiagnosis());
		tbPressure.setText(new Integer(tr.getVitalSigns().getBloodPressure()).toString());
		tbPulse.setText(new Integer(tr.getVitalSigns().getPulse()).toString());
		tbTemp.setText(new Double(tr.getVitalSigns().getTemp()).toString());
		tbHeight.setText(new Integer(tr.getVitalSigns().getHeight()).toString());
		tbWeight.setText(new Float(tr.getVitalSigns().getWeight()).toString());
		cmbDoctor.setSelectedItem((User.lookupUser(tr.getDoctor())));		//FIXXXX    this. Not selecting the item
		cmbNurse.setSelectedItem((User.lookupUser(tr.getNurse())));
		
		final Collection<DoctorsOrders> orders = DoctorsOrders.getDrsOrders(
				tr.getDoctorsOrders());
		if(orders.size() > 0) {

			final DoctorsOrders drOrders= orders.iterator().next();
			this.orders = drOrders;
			this.scripts = new ArrayList<Prescription>(Arrays.asList(
					drOrders.getPrescriptions()));
			this.procs = new ArrayList<Procedure>(Arrays.asList(
					drOrders.getProcedures()));
			
			tbFollowUp.setText(this.orders.getFollowUpInstructions());
			tbInstructions.setText(this.orders.getInstructions());
			
			bindDrLists();
		}
		else{
			Procedure defaultProcedure = new Procedure(Calendar.getInstance().getTime(), "Default Procedure", tr.getDoctor(),
					(float)15.0, tr.getPatientid());
			this.orders = new DoctorsOrders(defaultProcedure);
			this.orders.create();
			this.scripts = new ArrayList<Prescription>();
			this.procs = new ArrayList<Procedure>();
			
			bindDrLists();
		}
	}
	
	/**
	 * Method bindDrLists.
	 */
	private void bindDrLists() {

		final int scriptsIndex = lstScripts.getSelectedIndex();
		final int procsIndex = lstProcedures.getSelectedIndex();
		
		//bind procs
		final JListBinding<Procedure, List<Procedure>, JList> jListBinding =
			SwingBindings.createJListBinding(UpdateStrategy.READ, this.procs,
					lstProcedures);
		jListBinding.bind();
		
		//bind scripts
		final JListBinding<Prescription, List<Prescription>, JList> jListBindingScripts =
			SwingBindings.createJListBinding(UpdateStrategy.READ, this.scripts,
					lstScripts);
		jListBindingScripts.bind();
		
		lstScripts.setSelectedIndex(scriptsIndex);
		lstProcedures.setSelectedIndex(procsIndex);
		
	}
	/**
	 * Method addNewProc.
	 */
	private void addNewProc() {
		
		int doctorID = treatmentRecord.getDoctor();
		int patientID = treatmentRecord.getPatientid();
		Date procedureTime = Calendar.getInstance().getTime();
		
		procs.add(new Procedure(procedureTime,
				"New procedure", doctorID, 10,
				patientID));
	}
	/**
	 * Method currentScript.
	 * @return Prescription
	 */
	private Prescription currentScript() {
		if(lstScripts.getSelectedIndex() >= 0) {
			return (Prescription) lstScripts.getModel().getElementAt(
					lstScripts.getSelectedIndex());
		}
		else {
			return null;
		}
	}
	/**
	 * Method currentProc.
	 * @return Procedure
	 */
	private Procedure currentProc() {
		if(lstProcedures.getSelectedIndex() >= 0) {
			return (Procedure) lstProcedures.getModel().getElementAt(
					lstProcedures.getSelectedIndex());
		}
		else {
			return null;
		}
	}
	/**
	 * Method bindScript.
	 * @param script Prescription
	 */
	private void bindScript(Prescription script) {
		if(binding) {
			return;
		}
		
		tbDrugName.setText(script.getDrugName());
		tbPreInstructions.setText(script.getInstructions());
	}
	/**
	 * Method bindProc.
	 * @param proc Procedure
	 */
	private void bindProc(Procedure proc) {
		if(binding) {
			return;
		}
		tbProcedure.setText(proc.getProcedureName());
		tbCost.setText(new Float(proc.getCost()).toString());
	}
	
	/**
	 * Method save.
	 */
	private void save() {

		if(tbPressure.getText().equalsIgnoreCase("")) {
			tbPressure.setText("0");
		}
		if(tbPulse.getText().equalsIgnoreCase("")) {
			tbPulse.setText("0");
		}
		if(tbTemp.getText().equalsIgnoreCase("")) {
			tbTemp.setText("0");
		}
		if(tbHeight.getText().equalsIgnoreCase("")) {
			tbHeight.setText("0");
		}
		if(tbWeight.getText().equalsIgnoreCase("")) {
			tbWeight.setText("0");
		}
		
		final Date date = Calendar.getInstance().getTime();
		final String symptoms = tbSymptoms.getText();
		final String diagnosis = tbDiagnosis.getText();
		final int pressure = Integer.parseInt(tbPressure.getText());
		final int pulse  = Integer.parseInt(tbPulse.getText());
		final float temp = Float.parseFloat(tbTemp.getText());
		final int  height = Integer.parseInt(tbHeight.getText());
		final float weight = Float.parseFloat(tbWeight.getText());
		
		final VitalSigns vitalSigns = new VitalSigns(pressure, pulse, temp,
				height, weight);
		final int doctorID = ((User) cmbDoctor.getSelectedItem()).getUID();
		final int nurseID = ((User) cmbNurse.getSelectedItem()).getUID();
		
		Prescription[] prescArray;
		if(scripts != null && scripts.size() > 0){
			prescArray = new Prescription[scripts.size()];
			scripts.toArray(prescArray);
		}
		else{
			prescArray = new Prescription[0];
		}
		
		Procedure[] procArray;
		if(procs != null && procs.size() > 0){
			procArray = new Procedure[procs.size()];
			procs.toArray(procArray);
		}
		else{
			procArray = new Procedure[0];
		}
		
		final DoctorsOrders drOrders = new DoctorsOrders(prescArray, procArray,
				tbInstructions.getText(), tbFollowUp.getText());

		//read fields
		if(!update) {
			//create new tr
			drOrders.create();
			final TreatmentRecord tr = new TreatmentRecord(drOrders.getOrderID(),
					vitalSigns, doctorID, nurseID, patient.getPatientID(),
					date, diagnosis, symptoms);
			tr.create();
		}
		else {
			//save tr
			treatmentRecord.setDate(date);
			treatmentRecord.setDiagnosis(diagnosis);
			treatmentRecord.setSymptoms(symptoms);
			treatmentRecord.setVitalSigns(vitalSigns);
			treatmentRecord.setDoctor(doctorID);
			treatmentRecord.setNurse(nurseID);
			treatmentRecord.update();
			this.orders.setPrescriptions(prescArray);
			this.orders.setProcedures(procArray);
			this.orders.setFollowUpInstructions(tbFollowUp.getText());
			this.orders.setInstructions(tbInstructions.getText());
			this.orders.update();
			
		}
		setVisible(false);
		mainFrame.setVisible(true);
		mainFrame.rebindTRs();
	}
	/**
	 * Method cancel.
	 */
	private void cancel() {
		setVisible(false);
		mainFrame.setVisible(true);
	}
	/**
	 * Method delete.
	 */
	private void delete() {
		treatmentRecord.destroy();
		
		setVisible(false);
		mainFrame.setVisible(true);
		mainFrame.rebindTRs();
		
	}
	/**
	 * Method initDataBindings.
	 */
	protected void initDataBindings() {
		final JComboBoxBinding<User, List<User>, JComboBox> jComboBinding =
			SwingBindings.createJComboBoxBinding(UpdateStrategy.READ, doctors,
					cmbDoctor, "cmbBinding");
		jComboBinding.bind();
		//
		final JComboBoxBinding<User, List<User>, JComboBox> jComboBinding1 =
			SwingBindings.createJComboBoxBinding(UpdateStrategy.READ, nurses,
					cmbNurse, "cmbBinding");
		jComboBinding1.bind();
	}
}
